

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/Mine.jpg">
  <link rel="icon" href="/img/Mine.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Chiam">
  <meta name="keywords" content="算法，安全">
  
    <meta name="description" content="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。首先我们先讨论实体之间的联系怎么表示1.数据库中一对一的实现方式：（如一个学生对应一个档案，一个档案对应一个学生。学生表为 A 表，档案表为 B 表）  唯一外键方式：在 A 和 B 任意一表中添加唯一外键（注意是添加完外键后，再点唯一键，进行设置）具体方式点此。 主键关联方式：当 A 和 B 的主键相同时，我们就认为是一组数据。（注意">
<meta property="og:type" content="article">
<meta property="og:title" content="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。">
<meta property="og:url" content="http://example.com/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E5%85%A5%E9%97%A8%E5%BC%80%E5%8F%91%E6%A1%88%E4%BE%8B%EF%BC%8C%E7%9C%9F%E7%9A%84%E6%98%AF%E5%85%A5%E9%97%A8%E7%BA%A7%E5%88%AB%E7%9A%84%EF%BC%81%EF%BC%81%E7%9C%8B%E4%BA%86%E4%B8%8D%E5%90%8E%E6%82%94%E3%80%82/index.html">
<meta property="og:site_name" content="Chiam 的个人主页">
<meta property="og:description" content="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。首先我们先讨论实体之间的联系怎么表示1.数据库中一对一的实现方式：（如一个学生对应一个档案，一个档案对应一个学生。学生表为 A 表，档案表为 B 表）  唯一外键方式：在 A 和 B 任意一表中添加唯一外键（注意是添加完外键后，再点唯一键，进行设置）具体方式点此。 主键关联方式：当 A 和 B 的主键相同时，我们就认为是一组数据。（注意">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200521023802195.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200521023813903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200521023828689.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2023-12-05T16:11:43.873Z">
<meta property="article:modified_time" content="2023-12-05T16:18:12.606Z">
<meta property="article:author" content="Chiam">
<meta property="article:tag" content="算法，安全">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200521023802195.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
  
  
  
  <title>『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。 - Chiam 的个人主页</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/css/custom.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"❡"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Chiam&#39;s Blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-12-06 00:11" pubdate>
          2023年12月6日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.1k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          43 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。"><a href="#『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。" class="headerlink" title="『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。"></a>『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。</h1><h4 id="首先我们先讨论实体之间的联系怎么表示"><a href="#首先我们先讨论实体之间的联系怎么表示" class="headerlink" title="首先我们先讨论实体之间的联系怎么表示"></a>首先我们先讨论实体之间的联系怎么表示</h4><h6 id="1-数据库中一对一的实现方式："><a href="#1-数据库中一对一的实现方式：" class="headerlink" title="1.数据库中一对一的实现方式："></a>1.数据库中一对一的实现方式：</h6><p>（如一个学生对应一个档案，一个档案对应一个学生。学生表为 A 表，档案表为 B 表）</p>
<ul>
<li>唯一外键方式：在 A 和 B 任意一表中添加唯一外键（注意是添加完外键后，再点唯一键，进行设置）具体方式点此。</li>
<li>主键关联方式：当 A 和 B 的主键相同时，我们就认为是一组数据。（注意是“我们就认为”，数据库中并没有提供主键关联的约束方式。）</li>
<li>中间关系表：创建一张新表作为中间关系表，两个列分别记录 A 和 B，并且每一列的取值中，值均不能重复（即将这两列均设置为唯一外键，注意：将这两列“既设置为主键，又设置为外键”的方式不能实现该功能，因为可能会出现一列相等而另一列不相等的情况）。</li>
</ul>
<h6 id="2-数据库中一对多的实现方式："><a href="#2-数据库中一对多的实现方式：" class="headerlink" title="2.数据库中一对多的实现方式："></a>2.数据库中一对多的实现方式：</h6><p>（如一个班级对应多个学生）</p>
<ul>
<li>1 在多的一方添加外键：在学生表中添加一列，记录该学生是哪一个班的，该列设置成外键，取值为班级表的主键。</li>
<li>2 建立中间表：创建一个新表，该表至少有两列，分别记录学生和班级。学生列要设置成为“外键+唯一键”，以防有两行数据的学生列的值一样（防止一个学生有两个班级的情况出现）。班级列不必设置成唯一键，设置成为外键即可，因为不同学生可以有一样的班级。</li>
</ul>
<h6 id="3-数据库中多对多实现方式："><a href="#3-数据库中多对多实现方式：" class="headerlink" title="3.数据库中多对多实现方式："></a>3.数据库中多对多实现方式：</h6><p>（学生和课程：一个学生可以选多门课，一门课可以由多个学生选）</p>
<ul>
<li>1 建立中间关系表：新建一张表，一列记录学生，一列记录课程。两列均为外键，一列取值为学生表中的唯一标识，一列取值为课程中的唯一标识。两列不用设置成为唯一键，因为每一列中均可有重复，但不能有两行数据在两列上完全重复。所以将两列均设置成为主键+外键（即联合主键+外键）</li>
</ul>
<h5 id="然后我们给出案例"><a href="#然后我们给出案例" class="headerlink" title="然后我们给出案例"></a>然后我们给出案例</h5><p><strong>案例情景：</strong></p>
<ul>
<li>1）针对某个高校，开发一个学生成绩管理系统，要求设计出 ER 图。</li>
<li>2）针对目前疫情的情况，为某个小区设计一个人员管理的系统。</li>
<li>3）为教务处开发一个教室管理的系统。</li>
</ul>
<p><strong>数据库 ER 图:</strong></p>
<ol>
<li>学生成绩管理系统：<br><img src="https://img-blog.csdnimg.cn/20200521023802195.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></li>
<li>小区人员管理系统：<br><img src="https://img-blog.csdnimg.cn/20200521023813903.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></li>
<li>教室管理系统：<br><img src="https://img-blog.csdnimg.cn/20200521023828689.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></li>
</ol>
<p><strong>实现原理:</strong></p>
<ol>
<li>学生成绩管理系统：<ul>
<li><pre><code class="hljs">关系模式：
</code></pre>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs css">Student(Sid,Sname,Sgrade,Sclass,Smajor,Ssex): 学生信息表 <span class="hljs-built_in">Teacher</span>(<br>    Tid,<br>    Tname,<br>    Tdep<br>  ) ：教师信息表 <span class="hljs-built_in">Course</span>(Cid, Cno, Cname, Cscore) ：课程信息表 <span class="hljs-built_in">TC</span>(<br>    Tid,<br>    Cid,<br>    Cno<br>  ) ：教师课程关系表 (均为外码) <span class="hljs-built_in">SC</span>(Sid, Cid, Cno, Scj)<br>  ：学生课程成绩关系表(均为外码);<br></code></pre></td></tr></table></figure></li>
</ul>
</li>
</ol>
<ol start="2">
<li>MySQL 数据库实现：</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><code class="hljs css">Creat<br>database StuGrade;<br>use StuGrade<br>--建立一个学生信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Student<br>(<br>    Sid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,--主码<br>    Sname CHAR(<span class="hljs-number">10</span>),<br>    Sgrade INT,<br>    Sclass SMALLINT,<br>    Smajor CHAR(<span class="hljs-number">10</span>),<br>    Ssex BOOLEAN<br>);<br>--建立一个教师信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Teacher<br>(<br>    Tid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,<br>    --主码<br>    Tname CHAR(<span class="hljs-number">10</span>),<br>    Tdep CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个课程信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Course<br>(<br>    Cid CHAR(<span class="hljs-number">10</span>),<br><br>    Cno CHAR(<span class="hljs-number">10</span>),<br>    Cname CHAR(<span class="hljs-number">10</span>),<br>    Cscore SMALLINT ,<br>    PRIMARY KEY (Cid,Cno)<br>    --主码<br>);<br><br>--建立一个师课程关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> TC<br>(<br>    Tid CHAR(<span class="hljs-number">10</span>) ,<br>    --主码<br>    Cid CHAR(<span class="hljs-number">10</span>),<br>    Cno CHAR(<span class="hljs-number">10</span>),<br>    PRIMARY KEY (Tid,Cid,Cno),<br>    FOREIGN KEY (Tid) REFERENCES Teacher(Tid),<br>    FOREIGN KEY (Cid) REFERENCES Course(Cid),<br>    FOREIGN KEY (Cno) REFERENCES Course(Cno)<br>);<br>--建立一个学生课程成绩关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> SC<br>(<br>    Sid CHAR(<span class="hljs-number">10</span>),<br>    Cid CHAR(<span class="hljs-number">10</span>),<br>    Cno CHAR(<span class="hljs-number">10</span>),<br>    Scj SMALLINT,<br>    PRIMARY KEY (Sid,Cid,Cno),<br>    FOREIGN KEY (Sid) REFERENCES Student(Sid),<br>    FOREIGN KEY (Cid) REFERENCES Course(Cid),<br>    FOREIGN KEY (Cno) REFERENCES Course(Cno)<br>);<br></code></pre></td></tr></table></figure>

<p><strong>2. 小区人员管理系统：</strong></p>
<ol>
<li><p>关系模式：</p>
<pre><code class="hljs">Investigator(Iid,Iname,Ipho)：物业人员信息表
LocalPeople(LPid,LPname,LPpho,LPentertmp,LPwh)：小区常住人员	信息表
ForeignPeoPle(FPid,FPname,FPpho,FPtmp,FPperp)：外来人员信息表
Estate(Ecode,Eno,Eentra,Eloc)：住房信息
FtoL(FPid,LPid):访问关系信息表，均为外码
ImE(Iid,Eno)：管理关系，间接管理住户
LlE(Lid,Ecode):居住关系
</code></pre>
</li>
<li><p>MySQL 数据库实现：</p>
</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><code class="hljs css">Creat<br>database EstManage;<br>use EstManage<br>--建立一个 物业人员信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Investigator<br>(<br>    FPid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY ,<br>    FPpho CHAR(<span class="hljs-number">10</span>),<br>    FPtmp CHAR(<span class="hljs-number">10</span>),<br>    FPperp CHAR(<span class="hljs-number">200</span>),<br>);<br>--建立一个 小区常住人员信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> LocalPeople<br>(<br>    LPid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY ,<br>    LPname CHAR(<span class="hljs-number">10</span>),<br>    LPpho CHAR(<span class="hljs-number">10</span>),<br>    LPentertmp SMALLINT,<br>    LPwh boolean<br>);<br>--建立一个外来人员信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> ForeignPeoPle<br>(<br>    FPid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY ,<br>    FPname CHAR(<span class="hljs-number">10</span>),<br>    FPpho CHAR(<span class="hljs-number">10</span>),<br>    FPtmp CHAR(<span class="hljs-number">10</span>),<br>    FPperp CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个 住房信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Estate<br>(<br>    Ecode CHAR(<span class="hljs-number">10</span>) PRIMARY KEY ,<br>    Eno CHAR(<span class="hljs-number">10</span>) ,<br>    Eentra CHAR(<span class="hljs-number">10</span>)  ,<br>    Eloc CHAR(<span class="hljs-number">10</span>)<br>);<br><br>--建立一个访问关系信息表 关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> FtoL<br>(<br>    FPid CHAR(<span class="hljs-number">10</span>),<br>    LPid CHAR(<span class="hljs-number">10</span>),<br>    PRIMARY KEY (FPid,LPid),<br>    FOREIGN KEY (FPid) REFERENCES ForeignPeoPle(FPid),<br>    FOREIGN KEY (LPid) REFERENCES LocalPeople(LPid)<br><br>);<br>--建立一个管理关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> ImE<br>(<br>    Iid CHAR(<span class="hljs-number">10</span>),<br>    Eno CHAR(<span class="hljs-number">10</span>),<br>    PRIMARY KEY (Iid,Eno),<br>    FOREIGN KEY (Iid) REFERENCES Investigator(Iid),<br>    FOREIGN KEY (Eno) REFERENCES Estate(Eno),<br><br>);<br>--建立居住关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> LlE<br>(<br>    Lid CHAR(<span class="hljs-number">10</span>),<br>    Ecode CHAR(<span class="hljs-number">10</span>),<br>    PRIMARY KEY (Lid,Ecode),<br>    FOREIGN KEY (Lid) REFERENCES Teacher(Lid),<br>    FOREIGN KEY (Ecode) REFERENCES Course(Ecode),<br><br>);<br></code></pre></td></tr></table></figure>

<p><strong>3.教室管理系统：</strong></p>
<ol>
<li>关系模式：</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs css">Student(Sid,Sname,Sacademy): 学生信息表 <span class="hljs-built_in">Course</span>(Cno, Cname, Cscore, Cqual, Tname)<br>  ：课程信息表 <span class="hljs-built_in">Classroom</span>(CRno, CRstatus, CRtype) ：教室信息表 <span class="hljs-built_in">Building</span>(<br>    Bno,<br>    Bname,<br>    Bsum<br>  ) ：教学楼信息表 <span class="hljs-built_in">Campus</span>(CPno, CPname, CPlocation) ：校区信息表 <span class="hljs-built_in">STC</span>(<br>    Cno,<br>    CRno,<br>    Bno,<br>    Udate,<br>    UTime<br>  ) ：课程与教室使用关系表 <span class="hljs-built_in">SCR</span>(Sid, CRno, Bno Udate, UTime) ：学生借用教室关系表;<br></code></pre></td></tr></table></figure>

<ol start="2">
<li>MySQL 数据库实现：</li>
</ol>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><code class="hljs css">Creat<br>database ClassManage;<br>use ClassManage<br>--建立一个学生信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Student<br>(<br>    Sid CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,<br>    Sname CHAR(<span class="hljs-number">10</span>),<br>    Sacademy CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个  课程信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Course<br>(<br>    Cno CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,<br>    Cname CHAR(<span class="hljs-number">10</span>),<br>    Cscore CHAR(<span class="hljs-number">10</span>),<br>    Cqual CHAR(<span class="hljs-number">10</span>),<br>    Tname CHAR(<span class="hljs-number">10</span>)<br>);<br><br>--建立一个  教室信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Classroom<br>(<br>    CRno CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,<br>    CRstatus CHAR(<span class="hljs-number">10</span>),<br>    CRtype CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个  教学楼信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Building<br>(<br>    Bno CHAR(<span class="hljs-number">10</span>) PRIMARY KEY,<br>    Bname CHAR(<span class="hljs-number">10</span>),<br>    Bsum CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个  校区信息表<br>CREATE <span class="hljs-selector-tag">TABLE</span> Campus<br>(<br>    CPno CHAR(<span class="hljs-number">10</span>)PRIMARY KEY,<br>    CPname CHAR(<span class="hljs-number">10</span>),<br>    CPlocation CHAR(<span class="hljs-number">10</span>)<br>);<br>--建立一个 课程与教室使用关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> STC<br>(<br>    Cno CHAR(<span class="hljs-number">10</span>),<br>    CRno CHAR (<span class="hljs-number">10</span>),<br>    Bno CHAR (<span class="hljs-number">10</span>),<br>    Udate DATE,<br>    UTime <span class="hljs-selector-tag">TIME</span>,<br>    PRIMARY KEY (Cno,CRno,Bno,Udate,UTime),<br>    FOREIGN KEY (Cno) REFERENCES Course(Cno),<br>    FOREIGN KEY (CRno) REFERENCES Classroom(CRno),<br>    FOREIGN KEY (Bno) REFERENCES Building(Bno)<br><br>);<br>--建立一个  学生借用教室关系表<br>CREATE <span class="hljs-selector-tag">TABLE</span> SCR<br>(<br>    Sid CHAR(<span class="hljs-number">10</span>),<br>    CRno CHAR(<span class="hljs-number">10</span>),<br>    Bno CHAR(<span class="hljs-number">10</span>),<br>    Udate DATE,<br>    UTime <span class="hljs-selector-tag">TIME</span>,<br>    PRIMARY KEY (Sid,CRno,Bno,Udate,UTime),<br>    FOREIGN KEY (Sid) REFERENCES Student(Sid),<br>    FOREIGN KEY (CRno) REFERENCES Classroom(CRno),<br>    FOREIGN KEY (Bno) REFERENCES Building(Bno)<br><br>);<br><br></code></pre></td></tr></table></figure>

<blockquote>
<p><strong>写在最后：</strong><br>Name:风骨散人，喜欢码代码，码字，目前是一名双非在校大学生，预计考研，热爱编程，热爱技术，喜欢分享，知识无界，希望我的分享可以帮到你！名字的来源：我想有一天我能有能力随心所欲不逾矩，不总是向生活低头，有能力让家人拥有富足的生活而不是为了生计而到处奔波。<br><strong>文章主要内容：</strong><br>Python,C++,C 语言,JAVA,C#等语言的教程<br>ACM 题解、模板、算法等，主要是数据结构，数学和图论<br>设计模式，数据库，计算机网络，操作系统，计算机组成原理<br>Python 爬虫、深度学习、机器学习<br>计算机系<strong>408</strong>考研的所有专业课内容<br>一些程序猿常用的软件或者黑科技什么的<br><strong>目前还在更新中，先关注不迷路。微信公众号，cnblogs（博客园），CSDN 同名“风骨散人”</strong></p>
</blockquote>
<blockquote>
<p>如果有什么想看的，可以私信我，如果在能力范围内，我会发布相应的博文！<br>感谢大家的阅读！😘 你的点赞、收藏、关注是对我最大的鼓励！</p>
</blockquote>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" class="category-chain-item">数据库</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。</div>
      <div>http://example.com/2023/12/06/『数据库』数据库入门开发案例，真的是入门级别的！！看了不后悔。/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Chiam</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年12月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9A%84%E6%9F%A5%E8%AF%A2%E5%8F%AF%E4%B8%8D%E6%98%AF%E5%8F%AA%E7%9F%A5%E9%81%93Select%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9A%84-%E5%85%B3%E7%B3%BB%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B3%BB%E7%BB%9F%E7%9A%84%E6%9F%A5%E8%AF%A2%E5%A4%84%E7%90%86/" title="『数据库』数据库的查询可不是只知道Select就可以的-关系数据库系统的查询处理">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『数据库』数据库的查询可不是只知道Select就可以的-关系数据库系统的查询处理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E6%95%B0%E6%8D%AE%E5%BA%93SQL%E8%AF%AD%E8%A8%80%E4%BB%8E%E5%85%A5%E9%97%A8%E5%88%B0%E7%B2%BE%E9%80%9A-Part%206-%E5%8D%95%E8%A1%A8%E6%9F%A5%E8%AF%A2%EF%BC%88%E5%BF%AB%E6%9D%A5PICK%EF%BC%89/" title="『数据库』数据库SQL语言从入门到精通-Part 6-单表查询（快来PICK）">
                        <span class="hidden-mobile">『数据库』数据库SQL语言从入门到精通-Part 6-单表查询（快来PICK）</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fIfc7WqUDZohlQuPc2lz5mJy-MdYXbMMI","appKey":"zjlAG3ZA3o4cBHVAkjzc2Z20","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://fifc7wqu.api.lncldglobal.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <meta name="referrer" content="no-referrer" /> <footer id="footer" role="contentinfo"> <div class="divider"> <div class="wall"></div> <img class="animals" src="/img/footer_animals_new.png" srcset="/img/loading.gif" lazyload alt="Footer Animals"> </div> <div class="container" data-index="450"> <p> <a href="https://chiamzhang.github.io" target="_blank">DogEgg</a> <i class="iconfont icon-love"></i> <a href="#" target="_blank">LittePig</a> </p> <p> Powered by  <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-pen"></i> Theme  <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> </p> </div> </footer> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="/js/love.js"></script>
<script src="/js/funnyTitle.js"></script>
<script src="/js/backTop.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"left","width":150,"height":150,"hOffset":20,"vOffset":0},"mobile":{"show":false,"scale":0.5},"react":{"opacity":0.9},"log":false});</script></body>
</html>
